<!--# layout("/common/layout.html",{"jsBase":"/js/base/baseMessage/"}){ -->

<form class="layui-form layui-form-pane" id="addForm" enctype="multipart/form-data"  lay-filter="editform">

    <input type="hidden" name="messageId" id="messageId">

    <br/>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">消息标题</label>
				<div class="layui-input-inline">
                    <input type="text" name="title" id="title" autocomplete="off" maxlength="50" class="layui-input" lay-verify="required">
				</div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">消息类型</label>
                <div class="layui-input-inline">
                    <select name="type" lay-verify="required">
                        <option value="0">文本</option>
                        <option value="1">图文</option>
                        <option value="2">直播</option>
                        <option value="3">小程序</option>
                    </select>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">消息状态</label>
                <div class="layui-input-inline">
                    <select name="status" lay-verify="required ">
                        <option value="1">新建</option>
                        <option value="0">下线</option>
                        <option value="2">上线</option>
                    </select>
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">跳转地址</label>
                <div class="layui-input-inline">
                    <input type="text" name="href" id="href" autocomplete="off" maxlength="50" class="layui-input" >
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">省份</label>
                <div class="layui-input-inline">
                    <layui:simpleDataSelect name="provinceId" value="" data="${provinceList}"
                                            attrId="provId" attrName="provName" layFilter="colFilter" id="provinceId"  laySearch="true"/>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-input-inline">
             <label class="layui-form-label">归属模块</label>
                    <div class="layui-input-block" style="width:512px" id="modulecMember"></div>
            </div>

            <div class="layui-inline">
            <label class="layui-form-label">来源渠道</label>
				<div class="layui-input-inline">
                        <input type="text" name="channelCode" id="channelCode" autocomplete="off" maxlength="50" class="layui-input" >
				</div>
            </div>
        </div>
    </div>



    <layui:image id="img" tagName="消息小图" tips="可用于配置H5链接的分享图片 分辨率375*300"/>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">消息内容</label>
                <div class="layui-input-block" style="width:600px;z-index: 888">
                    <div id="contentDesc" ></div>
                    <input type="hidden" name="content" id="content"/>
                </div>
            </div>
        </div>
    </div>


    <layui:submitButtons id="addButton" />
</form>
<!--#} -->
<script type="text/javascript"  src="${ctxPath}/plugins/ueditor/ueditor.config.js"></script>
<script type="text/javascript"  src="${ctxPath}/plugins/ueditor/ueditor.all.js"></script>
<script>

    var ue = UE.getEditor('contentDesc',{
        toolbars: [["undo", "redo",
            "|", "fontsize", "forecolor", "bold", "italic", "underline",
            "|", "justifyleft", "justifycenter", "justifyright", "justifyjustify", "lineheight",
            "|", "directionalityltr", "directionalityrtl", "indent","|", "simpleupload",
            "|", "backcolor", "autotypeset", "spechars", "source",
            "|", "searchreplace", "|", "fullscreen","mobile"]],
        serverUrl: "${ctxPath}/content/ebookChapter/config",
        autoHeightEnabled: false,
        elementPathEnabled : false,　　//是否启用元素路径，默认是true显示
        wordCount:false,          //是否开启字数统计
        initialFrameHeight:300
    });
    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action) {
        if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadvideo') {
            return '${ctxPath}/content/ebookChapter/upload.json';
        } else {
            return this._bkGetActionUrl.call(this, action);
        }
    }
    Common.initImage();
layui.extend({
    loading: '../../../plugins/layui_extends/loading/loading',
    selectM: '../../../plugins/layui_extends/selectM',
}).define([ 'form', 'laydate', 'table','loading','baseMessageApi','selectM'], function(exports) {
    var form = layui.form;
    var baseMessageApi = layui.baseMessageApi;
    var index = layui.index;
    var selectM = layui.selectM;
    var isNew = true;
    var tagData = ${moduleJson};

    <!--# if(!(isEmpty(baseMessageJson))){  -->
    isNew = false;
    <!--# } -->
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            var tagIns2 = selectM({
                //元素容器【必填】
                elem: '#modulecMember'
                //候选数据【必填】
                ,data: tagData
                //默认值
                ,selected: [${baseMessage.module!}]
                //最多选中个数，默认5
                ,max : 5
                //input的name 不设置与选择器相同(去#.)
                ,name: 'module'
                //值的分隔符
                ,delimiter: ','
                //候选项数据的键名
                ,field: {idName:'dictId',titleName:'dictValue'}
            });
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                // $("#addButton").hide();
                // $("#addButton-loading").show();
                // $("#addButton-loading").loading();
                $("#content").val(ue.getContent());
                form.on('submit(form)', function(){
                    baseMessageApi.saveForm(isNew,$('#addForm'),function(){
                        parent.window.dataReload();
                        Common.info("保存成功");
                        Lib.closeFrame();
                    });
                });
            });

            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }

    }
    view.init();
    <!--# if(!(isEmpty(baseMessageJson))){  -->
    var formJson = ${baseMessageJson};
    form.val("editform",formJson);
    $(".image-preview").each(function() {
        $(this).attr("src",formJson[$(this).attr("id")]);
    });
    ue.setContent($("#content").val());
    <!--# } -->
});
</script>
